home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’93
/
PageTool 1.0
/
PagerPROAECalls.c
< prev
next >
Wrap
Text File
|
1993-06-17
|
14KB
|
418 lines
/************************************************************************************
*
* PagerPROAECalls.c : PagerPRO AppleEvent calls
*
* By : Haider A. Isa
*
* © Caravelle Networks Corp.
*
* April 15th, 1992
*
************************************************************************************/
#include <AppleEvents.h>
#include <PPCToolBox.h>
#include <Strings.h>
#include <Errors.h>
#include "PagerPROAECalls.h"
/* ============================================================================== */
/* A P P L E E V E N T S C A L L S */
/* ============================================================================== */
OSErr initPagerPROAEInterface ( portRefNum, userRefNum, targetAddress, theLocation, thePortInfo)
short portRefNum; /* Current application port number */
long *userRefNum; /* User ref num */
AEAddressDesc *targetAddress; /* Target application address */
LocationNameRec *theLocation; /* Source application location */
PortInfoRec *thePortInfo; /* Source application portinfo */
{
OSErr retError;
Str32 theLocNBPType;
unsigned long defUserRefNum;
Str32 userName;
PPCStartPBRec pbStart;
TargetID targetID;
/* select a PagerPRO to link too */
if ( (retError = PPCBrowser ( nil, nil, false, theLocation, thePortInfo, (PPCFilterProcPtr) &ppsPPCFilter, theLocNBPType)) == noErr )
{
userName [0] = 0;
defUserRefNum = 0;
retError = GetDefaultUser ( &defUserRefNum, userName);
pbStart.ioCompletion = nil;
pbStart.portRefNum = portRefNum;
pbStart.serviceType = ppcServiceRealTime;
pbStart.resFlag = 0;
pbStart.portName = &thePortInfo->name;
pbStart.locationName = theLocation;
pbStart.userData = nil;
pbStart.userRefNum = defUserRefNum;
/* try to establish a session */
retError = PPCStart ( &pbStart, false);
if ( retError == noErr && retError == guestNotAllowedErr )
{
/* save user ref num */
*userRefNum = pbStart.userRefNum;
/* prepare target address */
targetID.sessionID = pbStart.sessRefNum;
BlockMove ( &thePortInfo->name, &targetID.name, sizeof(PPCPortRec));
BlockMove ( theLocation, &targetID.location, sizeof(LocationNameRec));
retError = AECreateDesc ( typeTargetID, (Ptr) &targetID, sizeof(TargetID), targetAddress);
{ /* PROBLEM FIX:
We are making the following call so we will force the
authentication dialog to appear here. If we call
StartSecureSession the authentication dialog will be
displayed but it will also be displayed on the first
Apple event call. This is a known problem with PPC and AE.
We don't like this either.
*/
long retValue; /* Returned value */
Str255 errString; /* Returned error string */
/* the fastest call to fix the above problem */
doAddressExist ( (StringPtr) "\pany address", &retValue, targetAddress, errString);
}
}
}
return ( retError);
}
OSErr countAddressBookItems ( itemType, lSize, targetAddress, errString)
OSType itemType; /* Item to count */
long *lSize; /* Returned number of items */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
OSErr retError;
/* count the items in the AddressBook list */
retError = countListItems ( ADDRESSBOOK, itemType, lSize, targetAddress, errString);
return ( retError);
}
OSErr countSendQueueItems ( itemType, lSize, targetAddress, errString)
OSType itemType; /* Item to count */
long *lSize; /* Returned number of items */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
OSErr retError;
/* count the items in the SendQueue list */
retError = countListItems ( SENDQUEUESTATUS, itemType, lSize, targetAddress, errString);
return ( retError);
}
OSErr doAddressExist ( addString, retValue, targetAddress, errString)
StringPtr addString; /* User or group name */
long *retValue; /* Returned value */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
AppleEvent theAppleEvent;
AppleEvent reply;
AEDescList param1List;
AEDesc param1;
Size actualSize;
DescType returnedType;
OSErr retError;
errString [0] = 0;
reply.dataHandle = nil;
/* create a CoreEvent, DoObjectsExist */
retError = AECreateAppleEvent ( kCoreEventClass, kAEDoObjectsExist, targetAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
if ( retError == noErr )
{
/* param1: address name */
retError = AECreateList ( nil, 0, false, ¶m1List);
retError = AECreateDesc ( typeChar, (Ptr) &addString [1], addString [0], ¶m1);
retError = AEPutDesc ( ¶m1List, 0, ¶m1);
retError = AEPutParamDesc ( &theAppleEvent, keyDirectObject, ¶m1List);
/* send the event */
retError = AESend ( &theAppleEvent, &reply, kAEWaitReply + kAENeverInteract, kAENormalPriority, 120, nil, nil);
if ( retError == noErr )
{
/* get the size */
if ( AEGetParamPtr ( &reply, keyAEResult, typeLongInteger, &returnedType, (Ptr) retValue, sizeof(long), &actualSize) != noErr )
{
/* get the error message */
AEGetParamPtr ( &reply, keyErrorString, typeChar, &returnedType, (Ptr) errString, 255, &actualSize);
errString [actualSize] = nil;
c2pstr ( (Ptr) errString);
retError = errAEEventFailed;
}
}
if ( param1.dataHandle )
AEDisposeDesc ( ¶m1);
if ( reply.dataHandle )
AEDisposeDesc ( &reply);
}
return ( retError);
}
OSErr getAddressBookItem ( index, dataRecord, targetAddress, errString)
long index; /* Item index to read */
Ptr dataRecord; /* Returned read data */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
OSErr retError;
/* read an item form the AddressBook list */
retError = getListItem ( ADDRESSBOOK, index, dataRecord, sizeof(addressBookData), targetAddress, errString);
return ( retError);
}
OSErr getSendQueueItem ( index, dataRecord, targetAddress, errString)
long index; /* Item index to read */
Ptr dataRecord; /* Returned read data */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
OSErr retError;
/* read an item from the SendQueue list */
retError = getListItem ( SENDQUEUESTATUS, index, dataRecord, sizeof(sendQueueData), targetAddress, errString);
return ( retError);
}
OSErr sendMessage ( msgPriority, addString, msgString, targetAddress, errString)
OSType msgPriority; /* message priority */
StringPtr addString; /* User or Group name */
StringPtr msgString; /* Message */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
AppleEvent theAppleEvent;
AppleEvent reply;
AEDescList param1List;
AEDesc param1;
AEDescList param2List;
AEDesc param2;
AEDescList param3List;
AEDesc param3;
Size actualSize;
DescType returnedType;
OSErr retError;
errString [0] = 0;
reply.dataHandle = nil;
/* create a CoreEvent, SetData */
retError = AECreateAppleEvent ( kCoreEventClass, kAESetData, targetAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
if ( retError == noErr )
{
/* param1: priority */
retError = AECreateList ( nil, 0, false, ¶m1List);
retError = AECreateDesc ( typeChar, (Ptr) &msgPriority, sizeof(OSType), ¶m1);
retError = AEPutDesc ( ¶m1List, 0, ¶m1);
retError = AEPutParamDesc ( &theAppleEvent, keyDirectObject, ¶m1List);
/* param2: address name */
retError = AECreateList ( nil, 0, false, ¶m2List);
retError = AECreateDesc ( typeChar, (Ptr) &addString [1], addString [0], ¶m2);
retError = AEPutDesc ( ¶m2List, 0, ¶m2);
retError = AEPutParamDesc ( &theAppleEvent, keyAEName, ¶m2List);
/* param3: message */
retError = AECreateList ( nil, 0, false, ¶m3List);
retError = AECreateDesc ( typeChar, (Ptr) &msgString [1], msgString [0], ¶m3);
retError = AEPutDesc ( ¶m3List, 0, ¶m3);
retError = AEPutParamDesc ( &theAppleEvent, keyAEData, ¶m3List);
/* send the event */
retError = AESend ( &theAppleEvent, &reply, kAEWaitReply + kAENeverInteract, kAENormalPriority, 120, nil, nil);
if ( retError == noErr )
{
/* get the error message */
if ( AEGetParamPtr ( &reply, keyErrorString, typeChar, &returnedType, (Ptr) errString, 255, &actualSize) == noErr )
{
errString [actualSize] = nil;
c2pstr ( (Ptr) errString);
retError = errAEEventFailed;
}
}
if ( param1.dataHandle )
AEDisposeDesc ( ¶m1);
if ( param2.dataHandle )
AEDisposeDesc ( ¶m2);
if ( param3.dataHandle )
AEDisposeDesc ( ¶m3);
if ( reply.dataHandle )
AEDisposeDesc ( &reply);
}
return ( retError);
}
/* ============================================================================== */
/* S U P P O R T C A L L S */
/* ============================================================================== */
OSErr countListItems ( listType, itemType, lSize, targetAddress, errString)
OSType listType; /* List to look in */
OSType itemType; /* Item to count */
long *lSize; /* Returned number of items */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
AppleEvent theAppleEvent;
AppleEvent reply;
AEDescList param1List;
AEDesc param1;
AEDescList param2List;
AEDesc param2;
Size actualSize;
DescType returnedType;
OSErr retError;
errString [0] = 0;
*lSize = 0;
reply.dataHandle = nil;
/* create a CoreEvent, CountObjectElements */
retError = AECreateAppleEvent ( kCoreEventClass, kAECountElements, targetAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
if ( retError == noErr )
{
/* param1: listType */
retError = AECreateList ( nil, 0, false, ¶m1List);
retError = AECreateDesc ( typeChar, (Ptr) &listType, sizeof(OSType), ¶m1);
retError = AEPutDesc ( ¶m1List, 0, ¶m1);
retError = AEPutParamDesc ( &theAppleEvent, keyDirectObject, ¶m1List);
/* param2: itemType */
retError = AECreateList ( nil, 0, false, ¶m2List);
retError = AECreateDesc ( typeChar, (Ptr) &itemType, sizeof(OSType), ¶m2);
retError = AEPutDesc ( ¶m2List, 0, ¶m2);
retError = AEPutParamDesc ( &theAppleEvent, keyAEObjectClass, ¶m2List);
/* send the event */
retError = AESend ( &theAppleEvent, &reply, kAEWaitReply + kAENeverInteract, kAENormalPriority, 120, nil, nil);
if ( retError == noErr )
{
/* get the size */
if ( AEGetParamPtr ( &reply, keyAEResult, typeLongInteger, &returnedType, (Ptr) lSize, sizeof(long), &actualSize) != noErr )
{
/* get the error message */
AEGetParamPtr ( &reply, keyErrorString, typeChar, &returnedType, (Ptr) errString, 255, &actualSize);
errString [actualSize] = nil;
c2pstr ( (Ptr) errString);
retError = errAEEventFailed;
}
}
if ( param1.dataHandle )
AEDisposeDesc ( ¶m1);
if ( param2.dataHandle )
AEDisposeDesc ( ¶m2);
if ( reply.dataHandle )
AEDisposeDesc ( &reply);
}
return ( retError);
}
OSErr getListItem ( listType, index, dataRecord, dataSize, targetAddress, errString)
OSType listType; /* List to read from */
long index; /* Item index to read */
Ptr dataRecord; /* Returned data */
short dataSize; /* Requested data size */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
AppleEvent theAppleEvent;
AppleEvent reply;
AEDescList param1List;
AEDesc param1;
AEDescList param2List;
AEDesc param2;
Size actualSize;
DescType returnedType;
OSErr retError;
errString [0] = 0;
reply.dataHandle = nil;
/* create a CoreEvent, GetData */
retError = AECreateAppleEvent ( kCoreEventClass, kAEGetData, targetAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
if ( retError == noErr )
{
/* param1: listType */
retError = AECreateList ( nil, 0, false, ¶m1List);
retError = AECreateDesc ( typeChar, (Ptr) &listType, sizeof(OSType), ¶m1);
retError = AEPutDesc ( ¶m1List, 0, ¶m1);
retError = AEPutParamDesc ( &theAppleEvent, keyDirectObject, ¶m1List);
/* param2: index */
retError = AECreateList ( nil, 0, false, ¶m2List);
retError = AECreateDesc ( typeInteger, (Ptr) &index, sizeof(long), ¶m2);
retError = AEPutDesc ( ¶m2List, 0, ¶m2);
retError = AEPutParamDesc ( &theAppleEvent, keyAERequestType, ¶m2List);
/* send the event */
retError = AESend ( &theAppleEvent, &reply, kAEWaitReply + kAENeverInteract, kAENormalPriority, 120, nil, nil);
if ( retError == noErr )
{
/* get the size */
if ( AEGetParamPtr ( &reply, keyAEResult, typeAERecord, &returnedType, dataRecord, dataSize, &actualSize) != noErr )
{
/* get the error message */
AEGetParamPtr ( &reply, keyErrorString, typeChar, &returnedType, (Ptr) errString, 255, &actualSize);
errString [actualSize] = nil;
c2pstr ( (Ptr) errString);
retError = errAEEventFailed;
}
}
if ( param1.dataHandle )
AEDisposeDesc ( ¶m1);
if ( param2.dataHandle )
AEDisposeDesc ( ¶m2);
if ( reply.dataHandle )
AEDisposeDesc ( &reply);
}
return ( retError);
}
pascal Boolean ppsPPCFilter ( theLoc, thePortInfo)
LocationNamePtr theLoc;
PortInfoPtr thePortInfo;
{
OSType retType;
#pragma unused (theLoc)
/* only PagerPRO types */
if ( thePortInfo->name.portKindSelector == ppcByCreatorAndType )
{
if ( thePortInfo->name.u.port.creator == PAGERPROCREATOR )
return ( true);
}
else {
BlockMove ( &thePortInfo->name.u.portTypeStr [1], &retType, sizeof(OSType));
if ( retType == PAGERPROCREATOR )
return ( true);
}
return ( false);
}